package com.bank.controller;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidPooledConnection;
import com.bank.utils.CRUD;
import com.sun.rmi.rmid.ExecPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Map;

/**
 * @author 王迎澳
 * @version 1.0
 * @school hhu
 * @date 2022/6/22 11:13
 */
@Controller
public class FowardController {

    @Autowired
    DruidDataSource dataSource;

    @Autowired
    CRUD op;

    @RequestMapping("/hello")
    public String hello(){
        return "test";
    }

    @RequestMapping("/login")
    public String login() throws Exception {
//        DruidPooledConnection connection = dataSource.getConnection();
//        PreparedStatement preparedStatement = connection.prepareStatement("select * from t_fruit");
//        ResultSet resultSet = preparedStatement.executeQuery();
//        while (resultSet.next()) {
//            System.out.print(resultSet.getString(1)+" ");
//            System.out.print(resultSet.getString(2)+" ");
//            System.out.print(resultSet.getString(3)+" ");
//            System.out.print(resultSet.getString(4)+" ");
//            System.out.println(resultSet.getString(5));
//        }
        return "login";
    }

    @RequestMapping(value = "/register")
    public String register() {
        return "register";
    }

    @RequestMapping(value = "/user")
    public String user(@RequestParam("uId") String uid, Model model) {

        model.addAllAttributes(op.getUserInfo(uid));

        return "user";
    }

    @RequestMapping(value = "/")
    public String rootlogin() {

        return "login";
    }

}